package kafka;

import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.ListTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;

import java.util.Arrays;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;

/**
 * @author 颜培轩
 * @date 2018年08月14日  上午 09:08
 */
public class Admin {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        Properties props = new Properties();
        props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");

        AdminClient adminClient = AdminClient.create(props);
        adminClient.deleteTopics(Arrays.asList("test01"));
        adminClient.createTopics(Arrays.asList(new NewTopic("test01", 1, (short) 1)));
        ListTopicsResult listTopicsResult = adminClient.listTopics();
        Set<String> strings = listTopicsResult.names().get();
        adminClient.deleteTopics(Arrays.asList("test01"));
        System.out.println("strings = " + strings);
        // kafka-topics --zookeeper localhost:2181  --delete --topic "test01"
    }
}
